<template>
  <div class="reportFormPage">
    <div id="domid" class="report-dom">
      <el-row>
        <el-col :span="5" :offset="19">
          <div class="pageNumBox">
            <span>第</span>
            <span class="placeholder-min text-center">&nbsp;{{ form.page }}&nbsp;</span>
            <span>页，共</span>
            <span class="placeholder-min text-center">&nbsp;{{ form.totalPage }}&nbsp;</span>
            <span>页</span>
          </div>
        </el-col>
      </el-row>
      <div class="topTwoBox">
        <div class="centerName">水泥混凝土拌合物含气量试验检测记录</div>
        <div class="codeText">BGLQ05002F</div>
      </div>
      <div class="threeTopBox">
        <div class="left-border">
          <div class="box-title">检测单位名称：</div>
          <div class>{{ form.jiancdwmc }}</div>
        </div>
        <div class="right-border">
          <span>记录编号：</span>
          <span class="placeholder">{{ form.jilbh }}</span>
        </div>
      </div>
      <!-- .........................1111111111111111111111111111111......................................................... -->
      <div class="table-border">
        <table height="220px" class="top-table">
          <tbody>
            <tr>
              <td align="center" width="15%" height="25">
                <span style="width: 90px; display: inline-block">工程名称</span>
              </td>
              <td width="85%" class="text-center" colspan="3">
                <span>{{ form.gongcmc }}</span>
              </td>
            </tr>
            <tr>
              <td align="center" width="15%" height="25">
                <span style="width: 90px; display: inline-block">工程部位/用途</span>
              </td>
              <td width="85%" class="text-center" colspan="3">
                <span>{{ form.gongcbwyt }}</span>
              </td>
            </tr>
            <tr>
              <td height="25" align="center">样品信息</td>
              <td class="specimen-border" colspan="3">
                <span>样品名称：</span>
                <span :class="{ placeholder: !form.yangpmc }">{{ form.yangpmc }}</span>
                <span>；样品编号：</span>
                <span :class="{ 'placeholder-long': !form.yangpbh }">{{ form.yangpbh }}</span>
                <span>；样品数量：</span>
                <span :class="{ placeholder: !form.yangpsl }">{{ form.yangpsl }}</span>
                <span>；样品状态：</span>
                <span :class="{ placeholder: !form.yangpzt }">{{ form.yangpzt }}</span>
                <span>；来样时间：</span>
                <span :class="{ placeholder: !form.yangpsj }">{{ form.yangpsj }}</span>
              </td>
            </tr>
            <tr>
              <td height="25" align="center" width="15%">
                <span style="width: 90px; display: inline-block">试验检测日期</span>
              </td>
               <!-- <td width="35%" class="text-center">{{ form.shiyjcrq }}</td> -->                                            
 <td width="35%" class="text-center">
      <el-input v-model="form.shiyjcrq" />
</td>

              <td align="center" style="width: 15%">
                <span style="width: 90px; display: inline-block">试验条件</span>
              </td>
              <td v-if="isPdf" width="35%">
                温度：
                <span style="display: inline-block; width: 10%">{{ form.wend }}</span>
                ℃；湿度：
                <span style="display: inline-block; width: 10%">{{ form.xiangdsd }}</span
                >%RH
              </td>
              <td v-else width="35%">
                温度：
                <el-input :type="isPdf ? 'string' : 'number'" v-model="form.shiytjwd" class="height100" style="width: 15%" />℃；湿度：
                <el-input :type="isPdf ? 'string' : 'number'" v-model="form.shiytjsd" class="height100" style="width: 15%" />%RH
              </td>
            </tr>
            <tr>
              <td height="50" align="center" width="15%">
                <span style="width: 90px; display: inline-block">检测依据</span>
              </td>
              <td width="35%">
                <span v-if="isPdf">{{ form.jiancyj }}</span>
                <el-input v-else type="textarea" v-model="form.jiancyj" :rows="2" class="mark" @dblclick.native="showBsJiancyjView" readonly />
              </td>
              <td align="center" width="15%">
                <span style="width: 90px; display: inline-block">判定依据</span>
              </td>
              <td width="35%">
                <span v-if="isPdf">{{ form.pandyj }}</span>
                <el-input v-else type="textarea" v-model="form.pandyj" :rows="2" @dblclick.native="showBsJudgeBaseView" @focus="handleFocus('pandyj')" class="mark" />
              </td>
            </tr>
            <tr class="bottom-border">
              <td height="50" align="center">
                <div>主要仪器设备</div>
                <div>名称及编号</div>
              </td>
              <td colspan="3">
                <span v-if="isPdf">{{ form.zhuyyqsbmcjbh }}</span>
                <el-input v-else type="textarea" :rows="2" v-model="form.zhuyyqsbmcjbh" class="height100 width100 mark" @dblclick.native="showBsInstrumentView" readonly></el-input>
              </td>
            </tr>
          </tbody>
        </table>
        <!-- .................................22222222222222222222222222222222............................................... -->
        <table height="616px" class="middle-table">
          <tbody>
            <tr trindex="0">
              <td height="30" width="15%" colspan="2" align="center">取样地点</td>
              <td colspan="5">
                <el-input type="text" v-model="form.quydd" @keydown.native="handleKeyDown($event, 0, 0)" :ref="'0_0'" />
              </td>
              <td align="center" height="30" colspan="2">配合比编号</td>
              <td colspan="5">
                <el-input type="text" v-model="form.peihbbh" @keydown.native="handleKeyDown($event, 0, 1)" :ref="'0_1'" />
              </td>
            </tr>
            <tr trindex="1">
              <td rowspan="2" colspan="2" height="30">量体容积标定</td>
              <td colspan="3">量钵与玻璃板总质量（g）</td>
              <td colspan="2">水温(℃)</td>
              <td colspan="2">水的密度（g/cm3）</td>
              <td colspan="2">量钵、玻璃板和水总重(g)</td>
              <td colspan="3">量钵容积（L）</td>
            </tr>
            <tr trindex="2">
              <td colspan="3"><el-input type="Number" style="text-align: center" v-model="form.liangbyblbzzl" @blur="computeRongj" @keydown.native="handleKeyDown($event, 1, 0)" :ref="'1_0'" /></td>
              <td colspan="2">
                <el-select v-model="form.shuiw" class="hide-icon height100" placeholder @change="shuiwenChange">
                  <el-option v-for="(item, index) in shuiwenList" :key="index" :label="item.temp" :value="item.temp"></el-option>
                </el-select>
              </td>
              <td colspan="2">{{ form.shuidmd }}</td>
              <td colspan="2"><el-input type="Number" style="text-align: center" v-model="form.liangbblbhszz" @blur="computeRongj" @keydown.native="handleKeyDown($event, 1, 1)" :ref="'1_1'" /></td>
              <td colspan="3">{{ form.liangtrj }}</td>
            </tr>
            <tr trindex="4">
              <td width="100%" colspan="14" height="30">含气量标定</td>
            </tr>
            <tr trindex="5">
              <td colspan="2" rowspan="2">含气量标定</td>
              <td height="60">含气量0%压力表读数(MPa)</td>
              <td>含气量1%压力表读数(MPa)</td>
              <td>含气量2%压力表读数(MPa)</td>
              <td>含气量3%压力表读数(MPa)</td>
              <td>含气量4%压力表读数(MPa)</td>
              <td>含气量5%压力表读数(MPa)</td>
              <td>含气量6%压力表读数(MPa)</td>
              <td>含气量7%压力表读数(MPa)</td>
              <td>含气量8%压力表读数(MPa)</td>
              <td>含气量9%压力表读数(MPa)</td>
              <td colspan="2">含气量10%压力表读数（MPa）</td>
            </tr>
            <tr trindex="6">
              <td><el-input v-model="form.hanql0ylbds" @blur="setEcharts" @keydown.native="handleKeyDown($event, 2, 0)" :ref="'2_0'" /></td>
              <td><el-input v-model="form.hanql1ylbds" @blur="setEcharts" @keydown.native="handleKeyDown($event, 2, 1)" :ref="'2_1'" /></td>
              <td><el-input v-model="form.hanql2ylbds" @blur="setEcharts" @keydown.native="handleKeyDown($event, 2, 2)" :ref="'2_2'" /></td>
              <td><el-input v-model="form.hanql3ylbds" @blur="setEcharts" @keydown.native="handleKeyDown($event, 2, 3)" :ref="'2_3'" /></td>
              <td><el-input v-model="form.hanql4ylbds" @blur="setEcharts" @keydown.native="handleKeyDown($event, 2, 4)" :ref="'2_4'" /></td>
              <td><el-input v-model="form.hanql5ylbds" @blur="setEcharts" @keydown.native="handleKeyDown($event, 2, 5)" :ref="'2_5'" /></td>
              <td><el-input v-model="form.hanql6ylbds" @blur="setEcharts" @keydown.native="handleKeyDown($event, 2, 6)" :ref="'2_6'" /></td>
              <td><el-input v-model="form.hanql7ylbds" @blur="setEcharts" @keydown.native="handleKeyDown($event, 2, 7)" :ref="'2_7'" /></td>
              <td><el-input v-model="form.hanql8ylbds" @blur="setEcharts" @keydown.native="handleKeyDown($event, 2, 8)" :ref="'2_8'" /></td>
              <td><el-input v-model="form.hanql9ylbds" @blur="setEcharts" @keydown.native="handleKeyDown($event, 2, 9)" :ref="'2_9'" /></td>
              <td><el-input v-model="form.hanql10ylbds" @blur="setEcharts" @keydown.native="handleKeyDown($event, 2, 10)" :ref="'2_10'" /></td>
            </tr>
            <tr trindex="16">
              <td colspan="14" height="30" class="echarts-title">
                <div>含气量标定曲线</div>
              </td>
            </tr>
            <tr trindex="6">
              <td colspan="14" height="200" class="echarts-border">
                <table-line-log-more-chart
                  :className="'echarts-border'"
                  :chartData="chartData"
                  :xMin="chartData.xMin"
                  :xMax="chartData.xMax"
                  :yMin="chartData.yMin"
                  :yMax="chartData.yMax"
                  :interval="interval"
                  :yInterval="yInterval"
                  :isSmooth="true"
                />
              </td>
            </tr>

            <tr trindex="9">
              <td colspan="2" rowspan="2">仪器测定含气量</td>
              <td colspan="3">第一次含气量值(%)</td>
              <td colspan="3">第二次含气量值(%)</td>
              <td colspan="3">含气量平均值(%)</td>
              <td colspan="3">修正后含气量平均值(%)</td>
            </tr>
            <tr trindex="10">
              <td colspan="3"><el-input type="Number" v-model="form.yiqcdhql1" @blur="computeYiqhql" @keydown.native="handleKeyDown($event, 3, 0)" :ref="'3_0'" /></td>
              <td colspan="3"><el-input type="Number" v-model="form.yiqcdhql2" @blur="computeYiqhql" @keydown.native="handleKeyDown($event, 3, 1)" :ref="'3_1'" /></td>
              <td colspan="3">{{ form.hanqlpjz }}</td>
              <td colspan="3"><el-input style="text-align: center" v-model="form.xiuzhhqlpjz" @keydown.native="handleKeyDown($event, 3, 2)" :ref="'3_2'" /></td>
            </tr>
            <tr trindex="9">
              <td colspan="2" rowspan="2">集料含气量</td>
              <td colspan="3">第一次含气量值(%)</td>
              <td colspan="3">第二次含气量值(%)</td>
              <td colspan="3">含气量平均值(%)</td>
              <td colspan="3">修正后含气量平均值(%)</td>
            </tr>
            <tr trindex="10">
              <td colspan="3"><el-input type="Number" style="text-align: center" v-model="form.jilhql1" @blur="computejilhql" @keydown.native="handleKeyDown($event, 4, 0)" :ref="'4_0'" /></td>
              <td colspan="3"><el-input type="Number" style="text-align: center" v-model="form.jilhql2" @blur="computejilhql" @keydown.native="handleKeyDown($event, 4, 1)" :ref="'4_1'" /></td>
              <td colspan="3">{{ form.jilhqlpjz }}</td>
              <td colspan="3"><el-input style="text-align: center" v-model="form.jilxzhhqlpjz" @keydown.native="handleKeyDown($event, 4, 2)" :ref="'4_2'" /></td>
            </tr>
            <tr trindex="10">
              <td colspan="2">混凝土拌合物含气量（%）</td>
              <td colspan="12">{{ form.hunntbhwhql }}</td>
            </tr>
          </tbody>
        </table>
        <!-- .....................................................33333333333333333................................................... -->
        <table height="30px" class="bottom-table">
          <tbody>
            <tr>
              <td>
                <el-input :rows="2" type="textarea" v-model="form.fujsm" />
              </td>
            </tr>
          </tbody>
        </table>
      </div>
      <!-- .................................44444444444............................................. -->
      <table height="22px" class="transparent">
        <tbody>
          <tr>
            <td width="10%" align="right">检测：</td>
            <td width="15%" align="left"></td>
            <td width="10%" align="right">记录：</td>
            <td width="15%" align="left"></td>
            <td width="10%" align="right">复核：</td>
            <td align="left" width="15%"></td>
            <td width="10%">日期：</td>
            <td align="left" width="15%">
              <div style="display: inline-block; margin-left: 20px">年</div>
              <div style="display: inline-block; margin-left: 20px">月</div>
              <div style="display: inline-block ;margin-left: 20px">日</div>
            </td>
          </tr>
        </tbody>
      </table>
    </div>
    <bs-jiancyj-view ref="bsJiancyjViewRef" @select="selectJiancyj" :syType="syType"></bs-jiancyj-view>
    <bs-instrument-view ref="bsInstrumentViewRef" @select="selectInstrument"></bs-instrument-view>
    <bs-judge-base-view ref="bsJudgeBaseViewRef" @select="selectJudge" :syType="syType" />
    <bs-judge-base-edit-view ref="bsJudgeBaseEditViewRef" @submit="selectJudgeBaseEdit" :syType="syType" />
  </div>
</template>

<script>
import { getSnhntBhwhqlBsInfo } from "@/api/reportsnhnt/snhntBhwhqlBsInfo";
import decimal from "@/utils/big-decimal";
import Bus from "@/utils/bus";

import BsInstrumentView from "@/views/dept/bsInstrument/BsInstrumentView.vue";
import BsJiancyjView from "@/views/sycs/bsJiancyj/BsJiancyjView.vue";
import { computeBiQualification } from "@/api/sycs/biQualification";
import { emptyConvert, handleFocus, handleKeyDown } from "@/views/reportForms/utils";
import BsJudgeBaseView from "@/views/sycs/bsJudgeBase/BsJudgeBaseView";
import BsJudgeBaseEditView from "@/views/sycs/bsJudgeBase/BsJudgeBaseEditView";
import { listBySyTypeId } from "@/api/sycs/dataBase";
import TableLineLogMoreChart from "@/views/reportForms/components/TableLineLogMoreChart.vue";

export default {
  name: "snhntbhwhql",
  components: {
    BsInstrumentView,
    BsJiancyjView,
    BsJudgeBaseView,
    BsJudgeBaseEditView,
    TableLineLogMoreChart
  },
  data() {
    return {
      chartData: {
        xName: "压力表读数（MPa）",
        yName: "含气量（%）",
        seriesData: [],
        time: "",
        xMin: 0.0,
        xMax: 0.12,
        yMin: 0,
        yMax: 12
      },
      interval: 0.02,
      yInterval: 2,
      shuiwenList: [],
      jilbh: "",
      shuidmd: "",
      form: {
        hunntbhwhql: null,
        liangtrj: "",
        shiyrq: "2024年03月09日",
        gongcbwyt: "",
        jilbh: "",
        jiancdwmc: "山东路桥集团试验检测中心有限公司泰安高速公路施工总承包项目工地试验室",
        totalPage: "",
        page: "",
        jiancyj: "",
        zhuyyqsbmcjbh: "",
        gongcmc: "汾阳至石楼高速公路",
        yangpmc: "K39+820-K40+440原地面",
        yangpbh: "JTG/T 3610-2019",
        laiysj: "2022年03月09日",
        yangpsl: "3kg",
        yangpzt: "完好无损"
      },

      dateText: "2024年05月10日",
      readonly: false
    };
  },
  props: {
    excelId: {
      type: [String, Number],
      default: () => ""
    },
    syType: {
      type: [String, Number],
      default: () => ""
    },
    isPdf: {
      type: Boolean,
      default: () => false
    }
  },
  watch: {},
  created() {
    this.getShuiwenList();
    this.getInfo();
  },
  methods: {
    // 获取详情
    getInfo() {
      // if (!this.excelId) {
      //   return;
      // }
      getSnhntBhwhqlBsInfo(this.excelId || this.$defaultExcelId).then((response) => {
        this.form = response.data;
        if (!this.form.fujsm) {
          this.form.fujsm = "附加声明：";
        }
        this.setEcharts();
      });
    },

    submitForm() {
      return this.form;
    },
    // 显示检测依据列表
    showBsJiancyjView() {
      this.$refs.bsJiancyjViewRef.init(this.form.jiancyjIds);
    },
    // 检测依据选择
    selectJiancyj(info) {
      // this.$set(this.form, 'jiancyj', info.label);
      this.form.jiancyj = info.label;
      this.form.jiancyjIds = info.ids;
      Bus.$emit("setSnhntbhwhqlBgjcyj", { jiancyj: this.form.jiancyj, jiancyjIds: this.form.jiancyjIds });
    },
    // 仪器选择
    selectInstrument(info) {
      this.form.zhuyyqsbmcjbh = info.label;
      this.form.shebIds = info.ids;
      Bus.$emit("setSnhntbhwhqlBgZhuyyqsbmcjbh", { zhuyyqsbmcjbh: this.form.zhuyyqsbmcjbh, shebIds: this.form.shebIds });
    },
    // 显示仪器列表
    showBsInstrumentView() {
      this.$refs.bsInstrumentViewRef.init(this.form.shebIds);
    },

    // 显示判定依据列表
    showBsJudgeBaseView() {
      this.$refs.bsJudgeBaseViewRef.init(this.form.pandyjIds);
    },
    // 判断依据选择
    selectJudge(info) {
      if (!info || !info.label) {
        return;
      }
      if (!this.form.pandyj) {
        this.form.pandyj = info.label;
      } else {
        if (info && info.label) {
          this.form.pandyj += "、" + info.label;
        }
      }
      // 添加指标 info.list
      let keys = [];
      info.list.forEach((item) => {
       if (this.form.baDetailVos[item.refQualId] && this.form.baDetailVos[item.refQualId].jiancjg) {
          this.form.baDetailVos[item.refQualId].symbolValue = item.symbolValue;
          this.form.baDetailVos[item.refQualId].num1 = item.num1;
          this.form.baDetailVos[item.refQualId].num2 = item.num2;
          keys.push(item.refQualId);
        }
      });
      this.computeDetectionResult(keys);
    },
    // 计算检测结果
    computeDetectionResult(keys) {
      if (!keys || keys.length <= 0) {
        return;
      }
      const data = keys.map((key) => {
        const info = {
          ...this.form.baDetailVos[key],
          jiancjg: this.form.baDetailVos[key].jiancjg == "-" ? "" : this.form.baDetailVos[key].jiancjg
        };
        return info;
      });
      computeBiQualification(data).then((res) => {
        const returnData = res.data;
        returnData.forEach((item) => {
          if (!item.symbolValue && !item.num1 && !item.num2) {
            item.jiszb = "-";
          }
          item.jiancjg = item.jiancjg ? item.jiancjg : "-";
          this.form.baDetailVos[item.qualId] = item;
        });
      });
    },
    // 编辑单个技术指标后赋值
    selectJudgeBaseEdit(info) {
      if (info.qualId) {
        this.form.baDetailVos[info.qualId] = info;
      }
      this.computeDetectionResult([info.qualId]);
    },

    // 拼接图表数据
    setEcharts() {
      const arr = [];
      let xMax = 0;
      for (let i = 10; i >= 0; i--) {
        const count = this.form["hanql" + i + "ylbds"];
        if (count || count == 0) {
          arr.push([count, i]);
        }
        if (i == 10) {
          xMax = count;
        }
        if (count > xMax) {
          xMax = count;
        }
      }
      xMax = decimal.add(decimal.round(xMax, 3, "CEILING"), this.interval, 2);
      this.chartData.xMax = xMax;
      const chart1 = {
        data: arr,
        connectNulls: true,
        smooth: true,
        type: "line",
        symbol: "none"
      };
      this.chartData.seriesData = [chart1];
    },

    // 查询水的密度列表
    getShuiwenList() {
      listBySyTypeId({ syYjId: "281757153833" }).then((response) => {
        const data = response.data;
        this.shuiwenList = data.page.records;
      });
    },

    shuiwenChange() {
      const info = this.shuiwenList.find((item) => item.temp == this.form.shuiw);
      this.form.shuidmd = info.density;
      this.computeRongj();
    },

    computeRongj() {
      if (this.form.liangbyblbzzl && this.form.shuidmd && this.form.liangbblbhszz) {
        this.form.liangtrj = decimal.divide(decimal.subtract(parseFloat(this.form.liangbblbhszz), parseFloat(this.form.liangbyblbzzl), 10), parseFloat(this.form.shuidmd));
      } else {
        this.form.liangtrj = null;
      }
    },

    //仪器测定含气量
    computeYiqhql() {
      if (this.form.yiqcdhql1 && this.form.yiqcdhql2) {
        this.form.hanqlpjz = decimal.divide(decimal.add(this.form.yiqcdhql1, this.form.yiqcdhql2, 10), 2, 1);
      } else {
        this.form.hanqlpjz = null;
      }
      this.computeHanqil();
    },
    //计算集料含气量
    computejilhql() {
      if (this.form.jilhql1 && this.form.jilhql2) {
        this.form.jilhqlpjz = decimal.divide(decimal.add(this.form.jilhql1, this.form.jilhql2, 10), 2, 1);
      } else {
        this.form.jilhqlpjz = null;
      }
      this.computeHanqil();
    },

    computeHanqil() {
      if (this.form.jilhqlpjz && this.form.hanqlpjz) {
        this.form.hunntbhwhql = decimal.subtract(parseFloat(this.form.hanqlpjz), parseFloat(this.form.jilhqlpjz), 1);
      } else {
        this.form.hunntbhwhql = null;
      }
      Bus.$emit("setSnhnthql", this.form.hunntbhwhql);
    },

    handleFocus(event) {
      handleFocus(event, this.page, this.form[event]);
    },
    handleKeyDown(event, rowIndex, colIndex) {
      const maxArr = [1, 1, 10, 2, 2];
      const ref = handleKeyDown(event, rowIndex, colIndex, maxArr);
      if (this.$refs[ref]) {
        this.$refs[ref].focus();
      }
    }
  }
};
</script>

<style scoped lang="scss">
.echarts-border {
  width: calc(210mm - 40mm - 8px);
  height: 200px;
  padding: 2px !important;
  background-color: #ffffff !important;
}
</style>
